package com.huli.controller;

import com.huli.mapper.PatientMapper;
import com.huli.mapper.SysUserMapper;
import com.huli.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

@RestController
@RequestMapping("/hz/login")
public class LoginController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysUserMapper sysUserMapper;

    @RequestMapping("/loginPhone")
    public int login(@RequestParam("phone") String phone, @RequestParam("captcha") int captcha) throws Exception {
            boolean login = sysUserService.login(phone, captcha);
        if(!login){
            return 0;
        }else {
            return sysUserMapper.findid(phone);
        }
    }
    @RequestMapping("/crestecaptcha")
    public Map<String, Object> creteCaptcha(@RequestParam String phone) {
        HashMap<String, Object> response = new HashMap<>();
        try {
            sysUserService.creteCaptcha(phone);
            response.put("success",true);
            response.put("message","验证码发送成功");
        }catch (Exception e){
            response.put("success",false);
            response.put("message",e.getMessage());
        }
        return response;
    }
}
